{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'1.0.5'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.__version__"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 准备工作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 173,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "import pandas as pd\n",
    "peiqi_key = \"3d66b8511123af91a9b1bb9df9a3c5c6\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 地理编码/逆地理编码"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 地理编码\n",
    "\n",
    "> * A.结构化地址的定义： 首先，地址肯定是一串字符，内含国家、省份、城市、区县、城镇、乡村、街道、门牌号码、屋邨、大厦等建筑物名称。按照由大区域名称到小区域名称组合在一起的字符。一个有效的地址应该是独一无二的。注意：针对大陆、港、澳地区的地理编码转换时可以将国家信息选择性的忽略，但省、市、城镇等级别的地址构成是不能忽略的。暂时不支持返回台湾省的详细地址信息。\n",
    "\n",
    "> * B.地理编码URL:https://restapi.amap.com/v3/geocode/geo?parameters\n",
    "   \n",
    "\n",
    "> * C.关于request参数：\n",
    ">> * 必填：key address\n",
    ">> * 选填：city batch sig output callback\n",
    "> * D.requests.get()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'113.679287,23.632575'"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#地理编码函数\n",
    "def geo(key,address,city=None,sig=None,output=None,callback=None):\n",
    "    url=\"https://restapi.amap.com/v3/geocode/geo?parameters\"\n",
    "    params = {\n",
    "        \"key\":key,\n",
    "        \"address\":address,\n",
    "        \"sig\":sig,\n",
    "        \"output\":output,\n",
    "        \"callback\":callback\n",
    "    }\n",
    "    r = requests.get(url,params)\n",
    "    results = r.json()['geocodes'][0]['location']\n",
    "    return results\n",
    "\n",
    "geo(\"3d66b8511123af91a9b1bb9df9a3c5c6\",\"广东省广州市中山大学南方学院\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 175,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 地理编码 A-1\n",
    "address = \"广东省广州市中山大学南方学院\"  #address=\"中山大学南方学院\"不够结构化\n",
    "url_geo = \"https://restapi.amap.com/v3/geocode/geo?parameters\"\n",
    "params_geo = {\n",
    "    \"key\":peiqi_key,\n",
    "    \"address\":address\n",
    "}\n",
    "response = requests.get(url=url_geo,params=params_geo)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 176,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 176,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "response"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 177,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '1',\n",
       " 'info': 'OK',\n",
       " 'infocode': '10000',\n",
       " 'count': '1',\n",
       " 'geocodes': [{'formatted_address': '广东省广州市从化区中山大学南方学院',\n",
       "   'country': '中国',\n",
       "   'province': '广东省',\n",
       "   'citycode': '020',\n",
       "   'city': '广州市',\n",
       "   'district': '从化区',\n",
       "   'township': [],\n",
       "   'neighborhood': {'name': [], 'type': []},\n",
       "   'building': {'name': [], 'type': []},\n",
       "   'adcode': '440117',\n",
       "   'street': [],\n",
       "   'number': [],\n",
       "   'location': '113.679287,23.632575',\n",
       "   'level': '兴趣点'}]}"
      ]
     },
     "execution_count": 177,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results = response.json() \n",
    "results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 179,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'113.679287,23.632575'"
      ]
     },
     "execution_count": 179,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "中大南方_location=results['geocodes'][0]['location'] #取location值\n",
    "中大南方_location"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 逆地理编码 \n",
    "> * A.适用场景：将经纬度转换为详细结构化的地址，且返回附近周边的POI、AOI信息。\n",
    "    例如：116.480881,39.989410 转换地址描述后：北京市朝阳区阜通东大街6号\n",
    "\n",
    "> * B.逆地理编码URL:https://restapi.amap.com/v3/geocode/regeo?parameters\n",
    "   \n",
    "\n",
    "> * C.关于request参数：\n",
    ">> * 必填：key location（经纬度坐标）\n",
    ">> * 选填：radius poitype extensions batch roadlevel sig output callback homeorcorp\n",
    "> * D.requests.get()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 逆地理编码函数\n",
    "def regeo(key,location,extensions=\"base\",radius=None,poitype=None,batch=None,roadlevel=None,sig=None,output=None,callback=None,homeorcorp=None):\n",
    "    url = \"https://restapi.amap.com/v3/geocode/regeo?parameters\"\n",
    "    params = {\n",
    "        \"key\":key,\n",
    "        \"location\":location,\n",
    "        \"extensions\":extensions,\n",
    "        \"radius\":radius,\n",
    "        \"poitype\":poitype,\n",
    "        \"batch\":batch,\n",
    "        \"roadlevel\":roadlevel,\n",
    "        \"sig\":sig,\n",
    "        \"output\":output,\n",
    "        \"callback\":callback,\n",
    "        \"homeorcorp\":homeorcorp\n",
    "    }\n",
    "    r = requests.get(url,params)\n",
    "    results = r.json()\n",
    "    return results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '1',\n",
       " 'info': 'OK',\n",
       " 'infocode': '10000',\n",
       " 'regeocode': {'formatted_address': [],\n",
       "  'addressComponent': {'country': [],\n",
       "   'province': [],\n",
       "   'city': [],\n",
       "   'citycode': [],\n",
       "   'district': [],\n",
       "   'adcode': [],\n",
       "   'township': [],\n",
       "   'towncode': [],\n",
       "   'streetNumber': {'street': [],\n",
       "    'number': [],\n",
       "    'location': '中大南方_location',\n",
       "    'direction': [],\n",
       "    'distance': []}},\n",
       "  'pois': [],\n",
       "  'roads': [],\n",
       "  'roadinters': [],\n",
       "  'aois': []}}"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "regeo('3d66b8511123af91a9b1bb9df9a3c5c6','中大南方_location')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 121,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "url_regeo = \"https://restapi.amap.com/v3/geocode/regeo?parameters\"\n",
    "params_regeo = {\n",
    "    \"key\":peiqi_key,\n",
    "    \"location\":中大南方_location,\n",
    "    \"evtensions\":\"all\"\n",
    "}\n",
    "response = requests.get(url=url_regeo,params=params_regeo)\n",
    "response"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '1',\n",
       " 'regeocode': {'addressComponent': {'city': '广州市',\n",
       "   'province': '广东省',\n",
       "   'adcode': '440117',\n",
       "   'district': '从化区',\n",
       "   'towncode': '440117103000',\n",
       "   'streetNumber': {'number': '7号',\n",
       "    'location': '113.678600,23.633329',\n",
       "    'direction': '西北',\n",
       "    'distance': '109.203',\n",
       "    'street': '博学路'},\n",
       "   'country': '中国',\n",
       "   'township': '温泉镇',\n",
       "   'businessAreas': [[]],\n",
       "   'building': {'name': [], 'type': []},\n",
       "   'neighborhood': {'name': [], 'type': []},\n",
       "   'citycode': '020'},\n",
       "  'formatted_address': '广东省广州市从化区温泉镇中山大学南方学院'},\n",
       " 'info': 'OK',\n",
       " 'infocode': '10000'}"
      ]
     },
     "execution_count": 122,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result = response.json() \n",
    "result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 155,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广东省广州市从化区温泉镇中山大学南方学院'"
      ]
     },
     "execution_count": 155,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results['regeocode']['formatted_address']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 路径规划\n",
    "> * 1 步行\n",
    "> * 2 公交\n",
    "> * 3 驾车 "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 步行\n",
    "> * 1 URL:https://restapi.amap.com/v3/direction/walking?parameters\n",
    "> * 2 requests.\n",
    "> * 3 参数: \n",
    ">> * 必填:key origin(出发点:经纬度) destination(目的地：经纬度)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 166,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 数据准备：\n",
    "import requests,json\n",
    "origin = \"广东省广州市中山大学南方学院\"\n",
    "destination = \"广州市从化区龙岗\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 167,
   "metadata": {},
   "outputs": [],
   "source": [
    "def geocode(key,address,city=None,batch=None)->str:\n",
    "    url = \"https://restapi.amap.com/v3/geocode/geo?parameters\"\n",
    "    params = {\n",
    "        \"key\":key,\n",
    "        \"address\":address,\n",
    "        \"city\":city,\n",
    "        \"batch\":batch\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    results = response.json()['geocodes'][0]['location']\n",
    "    # 返回值\n",
    "    return results\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 168,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'113.679287,23.632575'"
      ]
     },
     "execution_count": 168,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "起始点_中大南方 = geocode(peiqi_key,origin)\n",
    "起始点_中大南方"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 169,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'113.668051,23.600869'"
      ]
     },
     "execution_count": 169,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "目的地_龙岗 = geocode(peiqi_key,destination)\n",
    "目的地_龙岗"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 170,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 170,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "url_walking = \"https://restapi.amap.com/v3/direction/walking?parameters\"\n",
    "params_walking = {\n",
    "    \"key\":peiqi_key,\n",
    "    \"origin\":起始点_中大南方,\n",
    "    \"destination\":目的地_龙岗\n",
    "}\n",
    "r=requests.get(url_walking,params_walking)\n",
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 171,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '1',\n",
       " 'info': 'ok',\n",
       " 'infocode': '10000',\n",
       " 'count': '1',\n",
       " 'route': {'origin': '113.679287,23.632575',\n",
       "  'destination': '113.668051,23.600869',\n",
       "  'paths': [{'distance': '4957',\n",
       "    'duration': '3966',\n",
       "    'steps': [{'instruction': '向东步行101米右转',\n",
       "      'orientation': '东',\n",
       "      'road': [],\n",
       "      'distance': '101',\n",
       "      'duration': '81',\n",
       "      'polyline': '113.679592,23.632491;113.680586,23.632522',\n",
       "      'action': '右转',\n",
       "      'assistant_action': [],\n",
       "      'walk_type': '0'},\n",
       "     {'instruction': '向南步行199米向右前方行走',\n",
       "      'orientation': '南',\n",
       "      'road': [],\n",
       "      'distance': '199',\n",
       "      'duration': '159',\n",
       "      'polyline': '113.680586,23.632522;113.680638,23.63214;113.680668,23.63174;113.680634,23.631541;113.68059,23.631437;113.68059,23.631437;113.680499,23.631241;113.680408,23.631094;113.680208,23.630842',\n",
       "      'action': '向右前方行走',\n",
       "      'assistant_action': [],\n",
       "      'walk_type': '0'},\n",
       "     {'instruction': '向西步行159米左转',\n",
       "      'orientation': '西',\n",
       "      'road': [],\n",
       "      'distance': '159',\n",
       "      'duration': '127',\n",
       "      'polyline': '113.680204,23.630838;113.680035,23.630773;113.680035,23.630773;113.679644,23.630638;113.679644,23.630638;113.679362,23.630521;113.679201,23.630473;113.679201,23.630473;113.679032,23.63043;113.679032,23.63043;113.67888,23.630404;113.67888,23.630404;113.678711,23.630365',\n",
       "      'action': '左转',\n",
       "      'assistant_action': [],\n",
       "      'walk_type': '0'},\n",
       "     {'instruction': '向南步行237米左转',\n",
       "      'orientation': '南',\n",
       "      'road': [],\n",
       "      'distance': '237',\n",
       "      'duration': '190',\n",
       "      'polyline': '113.678711,23.63036;113.678711,23.62934;113.678711,23.62934;113.678711,23.629193;113.678689,23.629084;113.678637,23.629023;113.678424,23.628902;113.678368,23.628841;113.678316,23.628724;113.678294,23.628611;113.678294,23.628611;113.678277,23.628372',\n",
       "      'action': '左转',\n",
       "      'assistant_action': [],\n",
       "      'walk_type': '0'},\n",
       "     {'instruction': '向南步行498米向右前方行走',\n",
       "      'orientation': '南',\n",
       "      'road': [],\n",
       "      'distance': '498',\n",
       "      'duration': '398',\n",
       "      'polyline': '113.678273,23.628368;113.678572,23.628338;113.678685,23.628307;113.678685,23.628307;113.678845,23.628234;113.679045,23.628073;113.679158,23.627964;113.679158,23.627964;113.679214,23.627869;113.679236,23.627778;113.67928,23.627526;113.679288,23.627322;113.679288,23.627322;113.679253,23.626853;113.679184,23.626623;113.679141,23.626497;113.679002,23.626259;113.678941,23.626176;113.678711,23.625977;113.67862,23.625864;113.678529,23.62572;113.678438,23.625191;113.678429,23.625056;113.678451,23.624939;113.678572,23.624657',\n",
       "      'action': '向右前方行走',\n",
       "      'assistant_action': [],\n",
       "      'walk_type': '0'},\n",
       "     {'instruction': '向西南步行722米左转',\n",
       "      'orientation': '西南',\n",
       "      'road': [],\n",
       "      'distance': '722',\n",
       "      'duration': '578',\n",
       "      'polyline': '113.678572,23.624653;113.678559,23.62451;113.678416,23.624323;113.678416,23.624323;113.677582,23.623793;113.676532,23.623346;113.676363,23.623255;113.676272,23.623151;113.676111,23.622834;113.676042,23.622739;113.67579,23.622483;113.675499,23.622279;113.675417,23.622174;113.675386,23.622088;113.675378,23.621836;113.675378,23.621836;113.675391,23.62161;113.675434,23.621476;113.675543,23.621359;113.675764,23.621181;113.675846,23.621089;113.675903,23.620994;113.675907,23.620855;113.675877,23.620725;113.675747,23.620547;113.675599,23.620373;113.675243,23.620013',\n",
       "      'action': '左转',\n",
       "      'assistant_action': [],\n",
       "      'walk_type': '0'},\n",
       "     {'instruction': '向东南步行412米向右前方行走',\n",
       "      'orientation': '东南',\n",
       "      'road': [],\n",
       "      'distance': '412',\n",
       "      'duration': '330',\n",
       "      'polyline': '113.675239,23.620009;113.67549,23.620013;113.675642,23.619991;113.675773,23.619948;113.676016,23.619796;113.676901,23.619193;113.677261,23.618785;113.678069,23.61783;113.678069,23.61783;113.678181,23.617656',\n",
       "      'action': '向右前方行走',\n",
       "      'assistant_action': [],\n",
       "      'walk_type': '0'},\n",
       "     {'instruction': '沿乌土街向南步行1381米右转',\n",
       "      'orientation': '南',\n",
       "      'road': '乌土街',\n",
       "      'distance': '1381',\n",
       "      'duration': '1105',\n",
       "      'polyline': '113.678181,23.617652;113.678095,23.617205;113.678051,23.617075;113.677973,23.616923;113.677743,23.616558;113.677609,23.616289;113.677391,23.615816;113.677339,23.615668;113.67714,23.614826;113.677049,23.614323;113.676927,23.613359;113.676845,23.612786;113.676602,23.611489;113.676415,23.610438;113.676411,23.610265;113.676411,23.610265;113.676489,23.609848;113.676502,23.609622;113.676493,23.609236;113.676415,23.608746;113.676415,23.608485;113.67648,23.60819;113.67661,23.607734;113.676819,23.606736;113.676862,23.606541;113.676914,23.606415;113.677014,23.606254;113.677535,23.605673',\n",
       "      'action': '右转',\n",
       "      'assistant_action': [],\n",
       "      'walk_type': '0'},\n",
       "     {'instruction': '沿乌土街向西南步行165米直行',\n",
       "      'orientation': '西南',\n",
       "      'road': '乌土街',\n",
       "      'distance': '165',\n",
       "      'duration': '132',\n",
       "      'polyline': '113.677535,23.605668;113.676988,23.605373;113.676402,23.605;113.676163,23.604887',\n",
       "      'action': '直行',\n",
       "      'assistant_action': [],\n",
       "      'walk_type': '0'},\n",
       "     {'instruction': '沿934县道向西步行118米直行',\n",
       "      'orientation': '西',\n",
       "      'road': '934县道',\n",
       "      'distance': '118',\n",
       "      'duration': '94',\n",
       "      'polyline': '113.676159,23.604883;113.675799,23.604805;113.675508,23.604779;113.675508,23.604779;113.675013,23.60474',\n",
       "      'action': '直行',\n",
       "      'assistant_action': [],\n",
       "      'walk_type': '0'},\n",
       "     {'instruction': '沿桃园东路向西南步行674米向右前方行走',\n",
       "      'orientation': '西南',\n",
       "      'road': '桃园东路',\n",
       "      'distance': '674',\n",
       "      'duration': '539',\n",
       "      'polyline': '113.675009,23.604735;113.674236,23.604683;113.673893,23.604618;113.673464,23.604492;113.673464,23.604492;113.67168,23.604006;113.671541,23.603958;113.671411,23.603854;113.671068,23.603472;113.670807,23.603264;113.670807,23.603264;113.670525,23.603073;113.6702,23.602904;113.6702,23.602904;113.670022,23.602795;113.670022,23.602795;113.669909,23.602682;113.669818,23.602517;113.669787,23.602413;113.669718,23.601901',\n",
       "      'action': '向右前方行走',\n",
       "      'assistant_action': [],\n",
       "      'walk_type': '0'},\n",
       "     {'instruction': '沿桃园东路向西南步行247米右转',\n",
       "      'orientation': '西南',\n",
       "      'road': '桃园东路',\n",
       "      'distance': '247',\n",
       "      'duration': '198',\n",
       "      'polyline': '113.669714,23.601897;113.66964,23.601771;113.66964,23.601771;113.669488,23.601558;113.669488,23.601558;113.668789,23.600859;113.668663,23.600768;113.668663,23.600768;113.668442,23.600647;113.667947,23.600417',\n",
       "      'action': '右转',\n",
       "      'assistant_action': [],\n",
       "      'walk_type': '0'},\n",
       "     {'instruction': '沿龙泉路向北步行44米到达目的地',\n",
       "      'orientation': '北',\n",
       "      'road': '龙泉路',\n",
       "      'distance': '44',\n",
       "      'duration': '35',\n",
       "      'polyline': '113.667943,23.600412;113.667812,23.600794',\n",
       "      'action': [],\n",
       "      'assistant_action': '到达目的地',\n",
       "      'walk_type': '0'}]}]}}"
      ]
     },
     "execution_count": 171,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 公交车"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> * 1 URL:https://restapi.amap.com/v3/direction/transit/integrated?parameters\n",
    "> * 2 requests.\n",
    "> * 3 参数: \n",
    ">> * 必填:key，origin(出发点:经纬度)，destination(目的地：经纬度)，city"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'geo'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-81-de275f5938db>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      2\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mpandas\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0mpd\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      3\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mrequests\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mjson\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m \u001b[1;32mimport\u001b[0m \u001b[0mgeo\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      5\u001b[0m \u001b[0mkey\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m\"3d66b8511123af91a9b1bb9df9a3c5c6\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'geo'"
     ]
    }
   ],
   "source": [
    "#准备工作\n",
    "import pandas as pd\n",
    "import requests,json\n",
    "import geo\n",
    "key=\"3d66b8511123af91a9b1bb9df9a3c5c6\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [],
   "source": [
    "#函数\n",
    "def bus(key,origin,destination,city):\n",
    "    url = \"https://restapi.amap.com/v3/direction/transit/integrated?parameters\"\n",
    "    params = {\n",
    "        \"key\":key,\n",
    "        \"origin\":origin,\n",
    "        \"destination\":destination,\n",
    "        \"city\":city\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    results = response.json()\n",
    "    return results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 139,
   "metadata": {},
   "outputs": [],
   "source": [
    "orign=\"广东省广州市暨南大学\"\n",
    "location_orgin = geo.geocode(key,origin)\n",
    "print(location_orgin)\n",
    "destination=\"广东省广州市猎德\"\n",
    "location_destination = geo.geocode(key,destination)\n",
    "print(location_destination)\n",
    "city=\"广州\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 143,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '0', 'info': 'INVALID_PARAMS', 'infocode': '20000'}"
      ]
     },
     "execution_count": 143,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bus(key,location_origin,location_destination,city)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 驾车"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> * 1 URL:https://restapi.amap.com/v3/direction/driving?parameters\n",
    "> * 2 requests.\n",
    "> * 3 参数: \n",
    ">> * 必填:key，origin(出发点:经纬度)，destination(目的地：经纬度)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 180,
   "metadata": {},
   "outputs": [],
   "source": [
    "#函数\n",
    "def drive(key,origin,destination):\n",
    "    url = \"https://restapi.amap.com/v3/direction/transit/integrated?parameters\"\n",
    "    params = {\n",
    "        \"key\":key,\n",
    "        \"origin\":origin,\n",
    "        \"destination\":destination\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    results = response.json()\n",
    "    return results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "drive( key,origin,destination)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 行政区域查询"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> *适用场景:帮助用户快速的查找特定的行政区域信息\n",
    "> * API文档：https://lbs.amap.com/api/webservice/guide/api/district\n",
    "> * URL:https://restapi.amap.com/v3/config/district?parameters\n",
    "> * requests.\n",
    "> * 参数: \n",
    ">> * 必填:key\n",
    ">> * 选填：keywords subdistrict(子级行政区) extensions page offset filter callback output\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [],
   "source": [
    "#准备工作\n",
    "import pandas as pd\n",
    "peiqi_key=\"3d66b8511123af91a9b1bb9df9a3c5c6\"\n",
    "import requests,json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [],
   "source": [
    "def car(key,keywords=None,subdistrict=None,extensions=None,page=None,offset=None,filter=None,callback=None,output=None):\n",
    "    url = \"https://restapi.amap.com/v3/config/district?parameters\"\n",
    "    params = {\n",
    "        \"key\":key,\n",
    "        \"keywords\":keywords,\n",
    "        \"subdistrict\":subdistrict,\n",
    "        \"extensions\":extensions,\n",
    "        \"page\":page,\n",
    "        \"offset\":offset,\n",
    "        \"filter\":filter,\n",
    "        \"callback\":callback,\n",
    "        \"output\":output\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    results = response.json()\n",
    "    return results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '1',\n",
       " 'info': 'OK',\n",
       " 'infocode': '10000',\n",
       " 'count': '2',\n",
       " 'suggestion': {'keywords': [], 'cities': []},\n",
       " 'districts': [{'citycode': '0411',\n",
       "   'adcode': '210202',\n",
       "   'name': '中山区',\n",
       "   'center': '121.64376,38.921553',\n",
       "   'level': 'district',\n",
       "   'districts': [{'citycode': '0411',\n",
       "     'adcode': '210202',\n",
       "     'name': '海军广场街道',\n",
       "     'center': '121.678,38.9339',\n",
       "     'level': 'street',\n",
       "     'districts': []},\n",
       "    {'citycode': '0411',\n",
       "     'adcode': '210202',\n",
       "     'name': '青泥洼桥街道',\n",
       "     'center': '121.63,38.9213',\n",
       "     'level': 'street',\n",
       "     'districts': []},\n",
       "    {'citycode': '0411',\n",
       "     'adcode': '210202',\n",
       "     'name': '桃源街道',\n",
       "     'center': '121.628,38.851',\n",
       "     'level': 'street',\n",
       "     'districts': []},\n",
       "    {'citycode': '0411',\n",
       "     'adcode': '210202',\n",
       "     'name': '人民路街道',\n",
       "     'center': '121.658,38.9465',\n",
       "     'level': 'street',\n",
       "     'districts': []},\n",
       "    {'citycode': '0411',\n",
       "     'adcode': '210202',\n",
       "     'name': '老虎滩街道',\n",
       "     'center': '121.722,38.8848',\n",
       "     'level': 'street',\n",
       "     'districts': []},\n",
       "    {'citycode': '0411',\n",
       "     'adcode': '210202',\n",
       "     'name': '昆明街道',\n",
       "     'center': '121.646,38.9093',\n",
       "     'level': 'street',\n",
       "     'districts': []},\n",
       "    {'citycode': '0411',\n",
       "     'adcode': '210202',\n",
       "     'name': '葵英街道',\n",
       "     'center': '121.645,38.906',\n",
       "     'level': 'street',\n",
       "     'districts': []},\n",
       "    {'citycode': '0411',\n",
       "     'adcode': '210202',\n",
       "     'name': '桂林街道',\n",
       "     'center': '121.659,38.9179',\n",
       "     'level': 'street',\n",
       "     'districts': []}]},\n",
       "  {'citycode': '0760',\n",
       "   'adcode': '442000',\n",
       "   'name': '中山市',\n",
       "   'center': '113.382391,22.521113',\n",
       "   'level': 'city',\n",
       "   'districts': [{'citycode': '0760',\n",
       "     'adcode': '442000',\n",
       "     'name': '三角镇',\n",
       "     'center': '113.416,22.7079',\n",
       "     'level': 'street',\n",
       "     'districts': []},\n",
       "    {'citycode': '0760',\n",
       "     'adcode': '442000',\n",
       "     'name': '横栏镇',\n",
       "     'center': '113.224,22.6048',\n",
       "     'level': 'street',\n",
       "     'districts': []},\n",
       "    {'citycode': '0760',\n",
       "     'adcode': '442000',\n",
       "     'name': '五桂山街道',\n",
       "     'center': '113.399,22.4847',\n",
       "     'level': 'street',\n",
       "     'districts': []},\n",
       "    {'citycode': '0760',\n",
       "     'adcode': '442000',\n",
       "     'name': '东升镇',\n",
       "     'center': '113.321,22.5607',\n",
       "     'level': 'street',\n",
       "     'districts': []},\n",
       "    {'citycode': '0760',\n",
       "     'adcode': '442000',\n",
       "     'name': '神湾镇',\n",
       "     'center': '113.376,22.2768',\n",
       "     'level': 'street',\n",
       "     'districts': []},\n",
       "    {'citycode': '0760',\n",
       "     'adcode': '442000',\n",
       "     'name': '火炬开发区街道',\n",
       "     'center': '113.42,22.5577',\n",
       "     'level': 'street',\n",
       "     'districts': []},\n",
       "    {'citycode': '0760',\n",
       "     'adcode': '442000',\n",
       "     'name': '小榄镇',\n",
       "     'center': '113.23,22.7026',\n",
       "     'level': 'street',\n",
       "     'districts': []},\n",
       "    {'citycode': '0760',\n",
       "     'adcode': '442000',\n",
       "     'name': '南朗镇',\n",
       "     'center': '113.482,22.519',\n",
       "     'level': 'street',\n",
       "     'districts': []},\n",
       "    {'citycode': '0760',\n",
       "     'adcode': '442000',\n",
       "     'name': '古镇镇',\n",
       "     'center': '113.167,22.6751',\n",
       "     'level': 'street',\n",
       "     'districts': []},\n",
       "    {'citycode': '0760',\n",
       "     'adcode': '442000',\n",
       "     'name': '民众镇',\n",
       "     'center': '113.499,22.6855',\n",
       "     'level': 'street',\n",
       "     'districts': []},\n",
       "    {'citycode': '0760',\n",
       "     'adcode': '442000',\n",
       "     'name': '港口镇',\n",
       "     'center': '113.354,22.6027',\n",
       "     'level': 'street',\n",
       "     'districts': []},\n",
       "    {'citycode': '0760',\n",
       "     'adcode': '442000',\n",
       "     'name': '石岐区街道',\n",
       "     'center': '113.405,22.5247',\n",
       "     'level': 'street',\n",
       "     'districts': []},\n",
       "    {'citycode': '0760',\n",
       "     'adcode': '442000',\n",
       "     'name': '三乡镇',\n",
       "     'center': '113.432,22.3879',\n",
       "     'level': 'street',\n",
       "     'districts': []},\n",
       "    {'citycode': '0760',\n",
       "     'adcode': '442000',\n",
       "     'name': '大涌镇',\n",
       "     'center': '113.297,22.4834',\n",
       "     'level': 'street',\n",
       "     'districts': []},\n",
       "    {'citycode': '0760',\n",
       "     'adcode': '442000',\n",
       "     'name': '南头镇',\n",
       "     'center': '113.328,22.6882',\n",
       "     'level': 'street',\n",
       "     'districts': []},\n",
       "    {'citycode': '0760',\n",
       "     'adcode': '442000',\n",
       "     'name': '黄圃镇',\n",
       "     'center': '113.329,22.7457',\n",
       "     'level': 'street',\n",
       "     'districts': []},\n",
       "    {'citycode': '0760',\n",
       "     'adcode': '442000',\n",
       "     'name': '东区街道',\n",
       "     'center': '113.4,22.5274',\n",
       "     'level': 'street',\n",
       "     'districts': []},\n",
       "    {'citycode': '0760',\n",
       "     'adcode': '442000',\n",
       "     'name': '坦洲镇',\n",
       "     'center': '113.38,22.2868',\n",
       "     'level': 'street',\n",
       "     'districts': []},\n",
       "    {'citycode': '0760',\n",
       "     'adcode': '442000',\n",
       "     'name': '阜沙镇',\n",
       "     'center': '113.34,22.6406',\n",
       "     'level': 'street',\n",
       "     'districts': []},\n",
       "    {'citycode': '0760',\n",
       "     'adcode': '442000',\n",
       "     'name': '西区街道',\n",
       "     'center': '113.314,22.5649',\n",
       "     'level': 'street',\n",
       "     'districts': []},\n",
       "    {'citycode': '0760',\n",
       "     'adcode': '442000',\n",
       "     'name': '板芙镇',\n",
       "     'center': '113.358,22.4068',\n",
       "     'level': 'street',\n",
       "     'districts': []},\n",
       "    {'citycode': '0760',\n",
       "     'adcode': '442000',\n",
       "     'name': '南区街道',\n",
       "     'center': '113.367,22.4892',\n",
       "     'level': 'street',\n",
       "     'districts': []},\n",
       "    {'citycode': '0760',\n",
       "     'adcode': '442000',\n",
       "     'name': '沙溪镇',\n",
       "     'center': '113.344,22.5248',\n",
       "     'level': 'street',\n",
       "     'districts': []},\n",
       "    {'citycode': '0760',\n",
       "     'adcode': '442000',\n",
       "     'name': '东凤镇',\n",
       "     'center': '113.308,22.6803',\n",
       "     'level': 'street',\n",
       "     'districts': []}]}]}"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "peiqi_key=\"3d66b8511123af91a9b1bb9df9a3c5c6\"\n",
    "car(peiqi_key,subdistrict=\"3\",keywords=\"中山\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 234,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 234,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "url_car = \"https://restapi.amap.com/v3/config/district?parameters\"\n",
    "params_car = {\n",
    "    \"key\":peiqi_key\n",
    "}\n",
    "response = requests.get(url=url_car,params=params_car)\n",
    "response"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 189,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '1',\n",
       " 'info': 'OK',\n",
       " 'infocode': '10000',\n",
       " 'count': '1',\n",
       " 'suggestion': {'keywords': [], 'cities': []},\n",
       " 'districts': [{'citycode': [],\n",
       "   'adcode': '100000',\n",
       "   'name': '中华人民共和国',\n",
       "   'center': '116.3683244,39.915085',\n",
       "   'level': 'country',\n",
       "   'districts': [{'citycode': [],\n",
       "     'adcode': '230000',\n",
       "     'name': '黑龙江省',\n",
       "     'center': '126.642464,45.756967',\n",
       "     'level': 'province',\n",
       "     'districts': []},\n",
       "    {'citycode': [],\n",
       "     'adcode': '440000',\n",
       "     'name': '广东省',\n",
       "     'center': '113.280637,23.125178',\n",
       "     'level': 'province',\n",
       "     'districts': []},\n",
       "    {'citycode': [],\n",
       "     'adcode': '410000',\n",
       "     'name': '河南省',\n",
       "     'center': '113.665412,34.757975',\n",
       "     'level': 'province',\n",
       "     'districts': []},\n",
       "    {'citycode': [],\n",
       "     'adcode': '150000',\n",
       "     'name': '内蒙古自治区',\n",
       "     'center': '111.670801,40.818311',\n",
       "     'level': 'province',\n",
       "     'districts': []},\n",
       "    {'citycode': [],\n",
       "     'adcode': '650000',\n",
       "     'name': '新疆维吾尔自治区',\n",
       "     'center': '87.617733,43.792818',\n",
       "     'level': 'province',\n",
       "     'districts': []},\n",
       "    {'citycode': [],\n",
       "     'adcode': '210000',\n",
       "     'name': '辽宁省',\n",
       "     'center': '123.429096,41.796767',\n",
       "     'level': 'province',\n",
       "     'districts': []},\n",
       "    {'citycode': [],\n",
       "     'adcode': '420000',\n",
       "     'name': '湖北省',\n",
       "     'center': '114.298572,30.584355',\n",
       "     'level': 'province',\n",
       "     'districts': []},\n",
       "    {'citycode': [],\n",
       "     'adcode': '610000',\n",
       "     'name': '陕西省',\n",
       "     'center': '108.948024,34.263161',\n",
       "     'level': 'province',\n",
       "     'districts': []},\n",
       "    {'citycode': [],\n",
       "     'adcode': '520000',\n",
       "     'name': '贵州省',\n",
       "     'center': '106.713478,26.578343',\n",
       "     'level': 'province',\n",
       "     'districts': []},\n",
       "    {'citycode': '021',\n",
       "     'adcode': '310000',\n",
       "     'name': '上海市',\n",
       "     'center': '121.472644,31.231706',\n",
       "     'level': 'province',\n",
       "     'districts': []},\n",
       "    {'citycode': [],\n",
       "     'adcode': '370000',\n",
       "     'name': '山东省',\n",
       "     'center': '117.000923,36.675807',\n",
       "     'level': 'province',\n",
       "     'districts': []},\n",
       "    {'citycode': [],\n",
       "     'adcode': '340000',\n",
       "     'name': '安徽省',\n",
       "     'center': '117.283042,31.86119',\n",
       "     'level': 'province',\n",
       "     'districts': []},\n",
       "    {'citycode': '023',\n",
       "     'adcode': '500000',\n",
       "     'name': '重庆市',\n",
       "     'center': '106.504962,29.533155',\n",
       "     'level': 'province',\n",
       "     'districts': []},\n",
       "    {'citycode': [],\n",
       "     'adcode': '540000',\n",
       "     'name': '西藏自治区',\n",
       "     'center': '91.132212,29.660361',\n",
       "     'level': 'province',\n",
       "     'districts': []},\n",
       "    {'citycode': [],\n",
       "     'adcode': '430000',\n",
       "     'name': '湖南省',\n",
       "     'center': '112.982279,28.19409',\n",
       "     'level': 'province',\n",
       "     'districts': []},\n",
       "    {'citycode': [],\n",
       "     'adcode': '460000',\n",
       "     'name': '海南省',\n",
       "     'center': '110.33119,20.031971',\n",
       "     'level': 'province',\n",
       "     'districts': []},\n",
       "    {'citycode': [],\n",
       "     'adcode': '630000',\n",
       "     'name': '青海省',\n",
       "     'center': '101.778916,36.623178',\n",
       "     'level': 'province',\n",
       "     'districts': []},\n",
       "    {'citycode': [],\n",
       "     'adcode': '350000',\n",
       "     'name': '福建省',\n",
       "     'center': '119.306239,26.075302',\n",
       "     'level': 'province',\n",
       "     'districts': []},\n",
       "    {'citycode': [],\n",
       "     'adcode': '640000',\n",
       "     'name': '宁夏回族自治区',\n",
       "     'center': '106.278179,38.46637',\n",
       "     'level': 'province',\n",
       "     'districts': []},\n",
       "    {'citycode': [],\n",
       "     'adcode': '450000',\n",
       "     'name': '广西壮族自治区',\n",
       "     'center': '108.320004,22.82402',\n",
       "     'level': 'province',\n",
       "     'districts': []},\n",
       "    {'citycode': [],\n",
       "     'adcode': '320000',\n",
       "     'name': '江苏省',\n",
       "     'center': '118.767413,32.041544',\n",
       "     'level': 'province',\n",
       "     'districts': []},\n",
       "    {'citycode': [],\n",
       "     'adcode': '330000',\n",
       "     'name': '浙江省',\n",
       "     'center': '120.153576,30.287459',\n",
       "     'level': 'province',\n",
       "     'districts': []},\n",
       "    {'citycode': [],\n",
       "     'adcode': '360000',\n",
       "     'name': '江西省',\n",
       "     'center': '115.892151,28.676493',\n",
       "     'level': 'province',\n",
       "     'districts': []},\n",
       "    {'citycode': '1886',\n",
       "     'adcode': '710000',\n",
       "     'name': '台湾省',\n",
       "     'center': '121.509062,25.044332',\n",
       "     'level': 'province',\n",
       "     'districts': []},\n",
       "    {'citycode': [],\n",
       "     'adcode': '130000',\n",
       "     'name': '河北省',\n",
       "     'center': '114.502461,38.045474',\n",
       "     'level': 'province',\n",
       "     'districts': []},\n",
       "    {'citycode': '1852',\n",
       "     'adcode': '810000',\n",
       "     'name': '香港特别行政区',\n",
       "     'center': '114.173355,22.320048',\n",
       "     'level': 'province',\n",
       "     'districts': []},\n",
       "    {'citycode': '1853',\n",
       "     'adcode': '820000',\n",
       "     'name': '澳门特别行政区',\n",
       "     'center': '113.54909,22.198951',\n",
       "     'level': 'province',\n",
       "     'districts': []},\n",
       "    {'citycode': [],\n",
       "     'adcode': '620000',\n",
       "     'name': '甘肃省',\n",
       "     'center': '103.823557,36.058039',\n",
       "     'level': 'province',\n",
       "     'districts': []},\n",
       "    {'citycode': [],\n",
       "     'adcode': '510000',\n",
       "     'name': '四川省',\n",
       "     'center': '104.065735,30.659462',\n",
       "     'level': 'province',\n",
       "     'districts': []},\n",
       "    {'citycode': [],\n",
       "     'adcode': '220000',\n",
       "     'name': '吉林省',\n",
       "     'center': '125.3245,43.886841',\n",
       "     'level': 'province',\n",
       "     'districts': []},\n",
       "    {'citycode': '022',\n",
       "     'adcode': '120000',\n",
       "     'name': '天津市',\n",
       "     'center': '117.190182,39.125596',\n",
       "     'level': 'province',\n",
       "     'districts': []},\n",
       "    {'citycode': [],\n",
       "     'adcode': '140000',\n",
       "     'name': '山西省',\n",
       "     'center': '112.549248,37.857014',\n",
       "     'level': 'province',\n",
       "     'districts': []},\n",
       "    {'citycode': [],\n",
       "     'adcode': '530000',\n",
       "     'name': '云南省',\n",
       "     'center': '102.712251,25.040609',\n",
       "     'level': 'province',\n",
       "     'districts': []},\n",
       "    {'citycode': '010',\n",
       "     'adcode': '110000',\n",
       "     'name': '北京市',\n",
       "     'center': '116.405285,39.904989',\n",
       "     'level': 'province',\n",
       "     'districts': []}]}]}"
      ]
     },
     "execution_count": 189,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "response.json()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 搜索POI"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 关键字搜寻"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1.关键字搜索：通过用POI的关键字进行条件搜索，例如：肯德基、朝阳公园等；同时支持设置POI类型搜索，例如：银行\n",
    "2.URL: https://restapi.amap.com/v3/place/text?parameters\n",
    "3.必填参数：key keywords types\n",
    "  选填：city citylimit children offset page extensions sig output callback\n",
    "4。requests.get()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [],
   "source": [
    "#数据准备\n",
    "import requests,json\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [],
   "source": [
    "def guanjian(key,keywords,types=None,city=None,citylimit=None,children=None,offset=None,page=None,extensions=None,sig=None,output=None,callback=None):\n",
    "    url=\"https://restapi.amap.com/v3/place/text?parameters\"\n",
    "    params={\n",
    "        \"key\":key,\n",
    "        \"keyword\":keyword,\n",
    "        \"types\":types,\n",
    "        \"city\":city,\n",
    "        \"citylimit\":citylimit,\n",
    "        \"children\":children,\n",
    "        \"offset\":offset,\n",
    "        \"page\":page,\n",
    "        \"extensions\":extensions,\n",
    "        \"sig\":sig,\n",
    "        \"output\":output,\n",
    "        \"callback\":callback\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    results = response.json()\n",
    "    return results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'suggestion': {'keywords': [], 'cities': []},\n",
       " 'count': '900',\n",
       " 'infocode': '10000',\n",
       " 'pois': [{'parent': [],\n",
       "   'address': '环市西路159号',\n",
       "   'distance': [],\n",
       "   'biz_ext': {'cost': [], 'rating': '4.0'},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': [],\n",
       "   'cityname': '广州市',\n",
       "   'type': '交通设施服务;火车站;火车站',\n",
       "   'photos': [{'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/f52359fd971703b060b84a694f71f752'},\n",
       "    {'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/48eae540e67481afe013c96b47cd2710'},\n",
       "    {'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/d4a18a693a527a3b9033044fd1e6457e'}],\n",
       "   'typecode': '150200',\n",
       "   'shopinfo': '2',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '越秀区',\n",
       "   'name': '广州站',\n",
       "   'location': '113.257331,23.149243',\n",
       "   'tel': '020-61357222;020-86661789',\n",
       "   'shopid': [],\n",
       "   'id': 'B00140WEW0'},\n",
       "  {'parent': [],\n",
       "   'address': '南站北路',\n",
       "   'distance': [],\n",
       "   'biz_ext': {'cost': [], 'rating': '3.5'},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': [],\n",
       "   'cityname': '广州市',\n",
       "   'type': '交通设施服务;火车站;火车站',\n",
       "   'photos': [{'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/e11c63f744659d152bb3d7057512a5ac'},\n",
       "    {'provider': [],\n",
       "     'title': '外景图',\n",
       "     'url': 'http://store.is.autonavi.com/showpic/072b43217a3aba263c5bae95bf708b1b'},\n",
       "    {'provider': [],\n",
       "     'title': '外景图',\n",
       "     'url': 'http://store.is.autonavi.com/showpic/5787639814453cc4caf6b0f10bd37b53'}],\n",
       "   'typecode': '150200',\n",
       "   'shopinfo': '2',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '番禺区',\n",
       "   'name': '广州南站',\n",
       "   'location': '113.269114,22.988374',\n",
       "   'tel': [],\n",
       "   'shopid': [],\n",
       "   'id': 'B00140VAP3'},\n",
       "  {'parent': [],\n",
       "   'address': '东站路1号',\n",
       "   'distance': [],\n",
       "   'biz_ext': {'cost': [], 'rating': []},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': [],\n",
       "   'cityname': '广州市',\n",
       "   'type': '交通设施服务;火车站;火车站',\n",
       "   'photos': [{'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/96e0a1abd535a35d466f3ea377fceb3d'},\n",
       "    {'provider': [],\n",
       "     'title': '外景图',\n",
       "     'url': 'http://store.is.autonavi.com/showpic/764ad172016ab981020c8fd5999965c9'},\n",
       "    {'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/3ba313ddb8ac43e51c481547d1c38650'}],\n",
       "   'typecode': '150200',\n",
       "   'shopinfo': '2',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '天河区',\n",
       "   'name': '广州东站',\n",
       "   'location': '113.324981,23.150597',\n",
       "   'tel': '020-87146222',\n",
       "   'shopid': [],\n",
       "   'id': 'B00140TY64'},\n",
       "  {'parent': [],\n",
       "   'address': '环市西路147-149号',\n",
       "   'distance': [],\n",
       "   'biz_ext': {'cost': [], 'rating': []},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': [],\n",
       "   'cityname': '广州市',\n",
       "   'type': '交通设施服务;长途汽车站;长途汽车站',\n",
       "   'photos': [{'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/b30c87641ef9bd9e2b9552d3b05fc915'},\n",
       "    {'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/8c8eea52c24e85960167749494fbc7f7'},\n",
       "    {'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/09093ca97e33ea3f19775c43e2b1eb2b'}],\n",
       "   'typecode': '150400',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '越秀区',\n",
       "   'name': '广东省汽车客运站',\n",
       "   'location': '113.252538,23.148388',\n",
       "   'tel': '020-86661297',\n",
       "   'shopid': [],\n",
       "   'id': 'B00140G3ML'},\n",
       "  {'parent': [],\n",
       "   'address': '站前路1号',\n",
       "   'distance': [],\n",
       "   'biz_ext': {'cost': [], 'rating': '3.5'},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': [],\n",
       "   'cityname': '广州市',\n",
       "   'type': '交通设施服务;火车站;火车站',\n",
       "   'photos': [{'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/1ac78da0f5f1e976c5c0daf566cfec7c'},\n",
       "    {'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/63a3705317fd6d0b0fa6942241689d73'},\n",
       "    {'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/b31ae80f21ced24ec93ac447b401e7a2'}],\n",
       "   'typecode': '150200',\n",
       "   'shopinfo': '2',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '花都区',\n",
       "   'name': '广州北站',\n",
       "   'location': '113.203846,23.377273',\n",
       "   'tel': '020-61356850',\n",
       "   'shopid': [],\n",
       "   'id': 'B00140UERW'},\n",
       "  {'parent': [],\n",
       "   'address': [],\n",
       "   'distance': [],\n",
       "   'biz_ext': {'cost': [], 'rating': []},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': [],\n",
       "   'cityname': '广州市',\n",
       "   'type': '交通设施服务;长途汽车站;长途汽车站',\n",
       "   'photos': [{'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/163019b964ac29272d57c268d6e5cc8f'},\n",
       "    {'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/439bf090e97d8853b074f6a517822fa9'},\n",
       "    {'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/7b552f8dac53f2ec7e3587bcbc96a984'}],\n",
       "   'typecode': '150400',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '白云区',\n",
       "   'name': '罗冲围客运站',\n",
       "   'location': '113.222668,23.148436',\n",
       "   'tel': '020-81982052',\n",
       "   'shopid': [],\n",
       "   'id': 'B00140L9WE'},\n",
       "  {'parent': [],\n",
       "   'address': '芳村大道西533号',\n",
       "   'distance': [],\n",
       "   'biz_ext': {'cost': [], 'rating': []},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': [],\n",
       "   'cityname': '广州市',\n",
       "   'type': '交通设施服务;长途汽车站;长途汽车站',\n",
       "   'photos': [{'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/15257580a09a8efb189234ff7e9a5a6d'},\n",
       "    {'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/0917f9efbcf7f069d9b984789fc00bf8'},\n",
       "    {'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/dee16c7c5f1b0a55e42291835dabec3a'}],\n",
       "   'typecode': '150400',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '荔湾区',\n",
       "   'name': '广州滘口汽车站',\n",
       "   'location': '113.208026,23.11439',\n",
       "   'tel': '020-81546602',\n",
       "   'shopid': [],\n",
       "   'id': 'B00140T0GG'},\n",
       "  {'parent': [],\n",
       "   'address': '站前路',\n",
       "   'distance': [],\n",
       "   'biz_ext': {'cost': [], 'rating': []},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': [],\n",
       "   'cityname': '广州市',\n",
       "   'type': '交通设施服务;火车站;火车站',\n",
       "   'photos': [{'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/128e6cac12b06f66e5b79f88425785ba'}],\n",
       "   'typecode': '150200',\n",
       "   'shopinfo': '2',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '荔湾区',\n",
       "   'name': '广州西站(暂停营业)',\n",
       "   'location': '113.244417,23.138102',\n",
       "   'tel': [],\n",
       "   'shopid': [],\n",
       "   'id': 'B00140UF98'},\n",
       "  {'parent': [],\n",
       "   'address': '燕岭路633号',\n",
       "   'distance': [],\n",
       "   'biz_ext': {'cost': [], 'rating': []},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': [],\n",
       "   'cityname': '广州市',\n",
       "   'type': '交通设施服务;长途汽车站;长途汽车站',\n",
       "   'photos': [{'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/e97ca81140c2fb97418a3cae980774a6'},\n",
       "    {'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/e13df47d2fb210b9e6dc72289db6a4d8'},\n",
       "    {'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/31ff23b6d39a6b67981058909b99e916'}],\n",
       "   'typecode': '150400',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '天河区',\n",
       "   'name': '天河汽车客运站',\n",
       "   'location': '113.342102,23.170997',\n",
       "   'tel': '020-37085070',\n",
       "   'shopid': [],\n",
       "   'id': 'B0014047B8'},\n",
       "  {'parent': [],\n",
       "   'address': '花东镇机场大道东888号',\n",
       "   'distance': [],\n",
       "   'biz_ext': {'cost': [], 'rating': '4.5'},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': [],\n",
       "   'cityname': '广州市',\n",
       "   'type': '交通设施服务;机场相关;飞机场',\n",
       "   'photos': [{'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/c7cbb3bf26254cad19ca996876fbb147'},\n",
       "    {'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/6c62285b25ff0b2a8923c0e4d55101c1'},\n",
       "    {'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/4e96fa099a22898bd2584ddb050b410e'}],\n",
       "   'typecode': '150104',\n",
       "   'shopinfo': '2',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '白云区',\n",
       "   'name': '广州白云国际机场',\n",
       "   'location': '113.307605,23.389929',\n",
       "   'tel': '020-96158',\n",
       "   'shopid': [],\n",
       "   'id': 'B00140NZIQ'},\n",
       "  {'parent': [],\n",
       "   'address': '环市西路158号',\n",
       "   'distance': [],\n",
       "   'biz_ext': {'cost': [], 'rating': []},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': [],\n",
       "   'cityname': '广州市',\n",
       "   'type': '交通设施服务;长途汽车站;长途汽车站',\n",
       "   'photos': [{'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/d01979847388c214eed17fc723e2539f'},\n",
       "    {'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/edf8ec8bbcb2979e73651f98e822dfc3'},\n",
       "    {'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/e32a9fcf2bfb1f5dff77d282ec31cc2d'}],\n",
       "   'typecode': '150400',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '越秀区',\n",
       "   'name': '流花车站(暂停营业)',\n",
       "   'location': '113.255575,23.147291',\n",
       "   'tel': [],\n",
       "   'shopid': [],\n",
       "   'id': 'B00140JRNE'},\n",
       "  {'parent': [],\n",
       "   'address': '广园中路283号',\n",
       "   'distance': [],\n",
       "   'biz_ext': {'cost': [], 'rating': []},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': [],\n",
       "   'cityname': '广州市',\n",
       "   'type': '交通设施服务;长途汽车站;长途汽车站',\n",
       "   'photos': [{'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/a8c7753bbbdcc99b58b35758749f9601'},\n",
       "    {'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/c20cfac14f337c1178188a272d6ccb9b'},\n",
       "    {'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/fd430818200f2e99d9b7c84e4d81fa07'}],\n",
       "   'typecode': '150400',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '白云区',\n",
       "   'name': '广园客运站(广园中路)',\n",
       "   'location': '113.272268,23.159212',\n",
       "   'tel': '020-86379888;020-86376666',\n",
       "   'shopid': [],\n",
       "   'id': 'B001400A1D'},\n",
       "  {'parent': [],\n",
       "   'address': '花地大道中51号(近地铁坑口站)',\n",
       "   'distance': [],\n",
       "   'biz_ext': {'cost': [], 'rating': []},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': [],\n",
       "   'cityname': '广州市',\n",
       "   'type': '交通设施服务;长途汽车站;长途汽车站',\n",
       "   'photos': [{'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/b17787ea64dd2e8ebb4f30e97b15dc0c'},\n",
       "    {'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/56ba7b4a7ae0a33dfc958bc6df6e617f'},\n",
       "    {'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/c0eb38f5c6adea59aa13333c90a9ebbf'}],\n",
       "   'typecode': '150400',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '荔湾区',\n",
       "   'name': '芳村汽车客运站',\n",
       "   'location': '113.234984,23.079895',\n",
       "   'tel': '020-81405555',\n",
       "   'shopid': [],\n",
       "   'id': 'B00140MVTW'},\n",
       "  {'parent': [],\n",
       "   'address': '从城大道28号',\n",
       "   'distance': [],\n",
       "   'biz_ext': {'cost': [], 'rating': []},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': [],\n",
       "   'cityname': '广州市',\n",
       "   'type': '交通设施服务;长途汽车站;长途汽车站',\n",
       "   'photos': [{'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/462f204807405f79f822710acae242fa'},\n",
       "    {'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/55b5cf3aa31058fe016cf6f3'},\n",
       "    {'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/ee5376d7cc32aa2c37f47431befd796c'}],\n",
       "   'typecode': '150400',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '从化区',\n",
       "   'name': '从化汽车站',\n",
       "   'location': '113.599374,23.528771',\n",
       "   'tel': '020-87990999',\n",
       "   'shopid': [],\n",
       "   'id': 'B00140V0TX'},\n",
       "  {'parent': [],\n",
       "   'address': '南洲路182号',\n",
       "   'distance': [],\n",
       "   'biz_ext': {'cost': [], 'rating': []},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': [],\n",
       "   'cityname': '广州市',\n",
       "   'type': '交通设施服务;长途汽车站;长途汽车站',\n",
       "   'photos': [{'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/b3dde7a824135a7bd763a16237860c12'},\n",
       "    {'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/f5f1cedc940cfd0e963297ee3e40bd17'},\n",
       "    {'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/bac381174dcf616a786cc555be115e17'}],\n",
       "   'typecode': '150400',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '海珠区',\n",
       "   'name': '海珠客运站',\n",
       "   'location': '113.299392,23.063172',\n",
       "   'tel': '020-84013301;020-84013330',\n",
       "   'shopid': [],\n",
       "   'id': 'B00140MX67'},\n",
       "  {'parent': [],\n",
       "   'address': '英东大道附近',\n",
       "   'distance': [],\n",
       "   'biz_ext': {'cost': [], 'rating': '3.0'},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': [],\n",
       "   'cityname': '广州市',\n",
       "   'type': '交通设施服务;长途汽车站;长途汽车站',\n",
       "   'photos': [{'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/64aa55b6ec079279e9d5846ef2b52b75'},\n",
       "    {'provider': [],\n",
       "     'title': '外景图',\n",
       "     'url': 'http://store.is.autonavi.com/showpic/b3c47629f9adeec486b014a7a3279ba5'},\n",
       "    {'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/c182c96e307072e085c1206e9917c35e'}],\n",
       "   'typecode': '150400',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '南沙区',\n",
       "   'name': '南沙客运站(英东大道)',\n",
       "   'location': '113.595148,22.76919',\n",
       "   'tel': '020-34684785;020-39091251',\n",
       "   'shopid': [],\n",
       "   'id': 'B00140UEKE'},\n",
       "  {'parent': [],\n",
       "   'address': '广卫路',\n",
       "   'distance': [],\n",
       "   'biz_ext': {'cost': [], 'rating': []},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': [],\n",
       "   'cityname': '广州市',\n",
       "   'type': '商务住宅;住宅区;住宅小区',\n",
       "   'photos': [{'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/72696841726d976a6205bdd6430cc939'},\n",
       "    {'provider': [],\n",
       "     'title': '外景图',\n",
       "     'url': 'http://store.is.autonavi.com/showpic/0594d21a53a32238503c824286b631fd'},\n",
       "    {'provider': [],\n",
       "     'title': '外景图',\n",
       "     'url': 'http://store.is.autonavi.com/showpic/179523e3a102c7e145ec271638833cd6'}],\n",
       "   'typecode': '120302',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '越秀区',\n",
       "   'name': '白云山小区',\n",
       "   'location': '113.30815,23.156537',\n",
       "   'tel': [],\n",
       "   'shopid': [],\n",
       "   'id': 'B00140U4CP'},\n",
       "  {'parent': [],\n",
       "   'address': '淘金路62',\n",
       "   'distance': [],\n",
       "   'biz_ext': {'cost': '73385.00', 'rating': []},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': [],\n",
       "   'cityname': '广州市',\n",
       "   'type': '商务住宅;住宅区;住宅小区',\n",
       "   'photos': [{'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/70bb9f0504e8951dca5888a7809f66eb'},\n",
       "    {'provider': [],\n",
       "     'title': '外景图',\n",
       "     'url': 'http://store.is.autonavi.com/showpic/55c651f56b61fd57695f90b166ca8d7a'},\n",
       "    {'provider': [],\n",
       "     'title': '外景图',\n",
       "     'url': 'http://store.is.autonavi.com/showpic/9ffc6f3b561748252558ae2b01d8ac65'}],\n",
       "   'typecode': '120302',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '越秀区',\n",
       "   'name': '淘金家园',\n",
       "   'location': '113.294831,23.14353',\n",
       "   'tel': [],\n",
       "   'shopid': [],\n",
       "   'id': 'B0FFF5UPAN'},\n",
       "  {'parent': [],\n",
       "   'address': '珠江东路28号',\n",
       "   'distance': [],\n",
       "   'biz_ext': {'cost': [], 'rating': []},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': [],\n",
       "   'cityname': '广州市',\n",
       "   'type': '商务住宅;楼宇;商务写字楼',\n",
       "   'photos': [{'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/5d7a5b8ab20b077c1cd4d4102a973eac'},\n",
       "    {'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/42d3fafe571bec1bf09af924d3bcc508'},\n",
       "    {'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://aos-cdn-image.amap.com/sns/ugccomment/39f190b9-c65b-4267-b930-05c0a47e796f.jpg'}],\n",
       "   'typecode': '120201',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '天河区',\n",
       "   'name': '越秀金融大厦',\n",
       "   'location': '113.326316,23.123981',\n",
       "   'tel': '020-88831118',\n",
       "   'shopid': [],\n",
       "   'id': 'B0FFFAKP5U'},\n",
       "  {'parent': [],\n",
       "   'address': '三元里大道',\n",
       "   'distance': [],\n",
       "   'biz_ext': {'cost': '20543.00', 'rating': []},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': [],\n",
       "   'cityname': '广州市',\n",
       "   'type': '商务住宅;住宅区;住宅区',\n",
       "   'photos': [{'provider': [],\n",
       "     'title': '外景图',\n",
       "     'url': 'http://store.is.autonavi.com/showpic/ca0939623b7164adbeee5d7cfdf9ff54'},\n",
       "    {'provider': [],\n",
       "     'title': '外景图',\n",
       "     'url': 'http://store.is.autonavi.com/showpic/0890755678792570d92e73c4d99f6c70'},\n",
       "    {'provider': [],\n",
       "     'title': '外景图',\n",
       "     'url': 'http://store.is.autonavi.com/showpic/3ead33c3ce73de627638c222d1ea3d68'}],\n",
       "   'typecode': '120300',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '白云区',\n",
       "   'name': '沙涌北',\n",
       "   'location': '113.250778,23.170572',\n",
       "   'tel': '13678968521',\n",
       "   'shopid': [],\n",
       "   'id': 'B0FFH8UJDC'}],\n",
       " 'status': '1',\n",
       " 'info': 'OK'}"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "guanjian(\"3d66b8511123af91a9b1bb9df9a3c5c6\",keywords=\"高校\",city=\"广州\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 周边搜索"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1.周边搜索\n",
    "2.URL: https://restapi.amap.com/v3/place/around?parameters \n",
    "3.必填参数：key location\n",
    "  选填：keywords types city radius sortrule offset page extensions sig output callback\n",
    "4.requests.get()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests,json\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "def arround(key,location,keywords=None,types=None,city=None,radius=None,sortrule=None,offset=None,page=None,extensions=None,sig=None,output=None,callback=None):\n",
    "    url=\"https://restapi.amap.com/v3/place/around?parameters\"\n",
    "    params={\n",
    "        \"key\":key,\n",
    "        \"location\":location,\n",
    "        \"keywords\":keywords,\n",
    "        \"types\":types,\n",
    "        \"city\":city,\n",
    "        \"radius\":radius,\n",
    "        \"sortrule\":sortrule,\n",
    "        \"offset\":offset,\n",
    "        \"page\":page,\n",
    "        \"extensions\":extensions,\n",
    "        \"sig\":sig,\n",
    "        \"output\":output,\n",
    "        \"callback\":callback\n",
    "    }\n",
    "    response=requests.get(url,params=params)\n",
    "    results=response.json()\n",
    "    return results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'suggestion': {'keywords': [], 'cities': []},\n",
       " 'count': '297',\n",
       " 'infocode': '10000',\n",
       " 'pois': [{'parent': [],\n",
       "   'address': '温泉镇笃行路20、22、24号中山大学南方学院',\n",
       "   'distance': '0',\n",
       "   'biz_ext': {'cost': [], 'rating': []},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': [],\n",
       "   'cityname': '广州市',\n",
       "   'type': '生活服务;共享设备;充电宝',\n",
       "   'photos': [],\n",
       "   'typecode': '072101',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '从化区',\n",
       "   'name': '街电(榴芒一族中山大学南方学院店)',\n",
       "   'location': '113.679287,23.632575',\n",
       "   'tel': [],\n",
       "   'shopid': [],\n",
       "   'id': 'B0FFLB846S'},\n",
       "  {'parent': [],\n",
       "   'address': '从化温泉镇中山大学南方学院博学路6号',\n",
       "   'distance': '0',\n",
       "   'biz_ext': {'cost': [], 'rating': [], 'meal_ordering': '0'},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': 'diner',\n",
       "   'cityname': '广州市',\n",
       "   'type': '餐饮服务;中餐厅;特色/地方风味餐厅',\n",
       "   'photos': [],\n",
       "   'typecode': '050118',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '从化区',\n",
       "   'name': '爽爽石磨肠粉',\n",
       "   'location': '113.679287,23.632575',\n",
       "   'tel': '18218913303',\n",
       "   'shopid': [],\n",
       "   'id': 'B0FFKX3T5Y'},\n",
       "  {'parent': [],\n",
       "   'address': '温泉镇中山大学南方学院明辨路2号二、三层',\n",
       "   'distance': '0',\n",
       "   'biz_ext': {'cost': [], 'rating': [], 'meal_ordering': '0'},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': 'diner',\n",
       "   'cityname': '广州市',\n",
       "   'type': '餐饮服务;餐饮相关场所;餐饮相关',\n",
       "   'photos': [],\n",
       "   'typecode': '050000',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '从化区',\n",
       "   'name': '避风塘',\n",
       "   'location': '113.679286,23.632574',\n",
       "   'tel': [],\n",
       "   'shopid': [],\n",
       "   'id': 'B0FFKT2R96'},\n",
       "  {'parent': [],\n",
       "   'address': '温泉镇中山大学南方学院明辨路2号二、三层',\n",
       "   'distance': '0',\n",
       "   'biz_ext': {'cost': [], 'rating': [], 'meal_ordering': '0'},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': 'diner',\n",
       "   'cityname': '广州市',\n",
       "   'type': '餐饮服务;餐饮相关场所;餐饮相关',\n",
       "   'photos': [],\n",
       "   'typecode': '050000',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '从化区',\n",
       "   'name': 'slim tea',\n",
       "   'location': '113.679286,23.632574',\n",
       "   'tel': '18944690066',\n",
       "   'shopid': [],\n",
       "   'id': 'B0FFKSLFAN'},\n",
       "  {'parent': [],\n",
       "   'address': '温泉镇中山大学南方学院后门润泰超市一楼05号商铺',\n",
       "   'distance': '0',\n",
       "   'biz_ext': {'cost': [], 'rating': [], 'meal_ordering': '0'},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': 'diner',\n",
       "   'cityname': '广州市',\n",
       "   'type': '餐饮服务;中餐厅;特色/地方风味餐厅',\n",
       "   'photos': [],\n",
       "   'typecode': '050118',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '从化区',\n",
       "   'name': '劲酷烤吧',\n",
       "   'location': '113.679286,23.632573',\n",
       "   'tel': '13719231627',\n",
       "   'shopid': [],\n",
       "   'id': 'B0G3AYBO5X'},\n",
       "  {'parent': [],\n",
       "   'address': '温泉镇中山大学南方学院后门润泰超市一楼05号商铺',\n",
       "   'distance': '0',\n",
       "   'biz_ext': {'cost': [], 'rating': [], 'meal_ordering': '0'},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': 'diner',\n",
       "   'cityname': '广州市',\n",
       "   'type': '餐饮服务;中餐厅;广东菜(粤菜)',\n",
       "   'photos': [],\n",
       "   'typecode': '050103',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '从化区',\n",
       "   'name': '东记乡村美食',\n",
       "   'location': '113.679286,23.632573',\n",
       "   'tel': '13922398107',\n",
       "   'shopid': [],\n",
       "   'id': 'B0G3APADKJ'},\n",
       "  {'parent': [],\n",
       "   'address': '温泉镇中山大学南方学院后门润泰超市一楼05号商铺',\n",
       "   'distance': '0',\n",
       "   'biz_ext': {'cost': [], 'rating': [], 'meal_ordering': '0'},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': 'diner',\n",
       "   'cityname': '广州市',\n",
       "   'type': '餐饮服务;快餐厅;快餐厅',\n",
       "   'photos': [],\n",
       "   'typecode': '050300',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '从化区',\n",
       "   'name': '北方饺子馆',\n",
       "   'location': '113.679286,23.632573',\n",
       "   'tel': '13434241448',\n",
       "   'shopid': [],\n",
       "   'id': 'B0G2Z7IX80'},\n",
       "  {'parent': [],\n",
       "   'address': '温泉镇中山大学南方学院后门润泰超市一楼05号商铺',\n",
       "   'distance': '0',\n",
       "   'biz_ext': {'cost': [], 'rating': [], 'meal_ordering': '0'},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': 'diner',\n",
       "   'cityname': '广州市',\n",
       "   'type': '餐饮服务;餐饮相关场所;餐饮相关',\n",
       "   'photos': [],\n",
       "   'typecode': '050000',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '从化区',\n",
       "   'name': '第1烤场',\n",
       "   'location': '113.679286,23.632573',\n",
       "   'tel': '13538825321',\n",
       "   'shopid': [],\n",
       "   'id': 'B0G2K6PX0X'},\n",
       "  {'parent': [],\n",
       "   'address': '温泉镇中山大学南方学院后门润泰超市一楼05号商铺',\n",
       "   'distance': '0',\n",
       "   'biz_ext': {'cost': [], 'rating': [], 'meal_ordering': '0'},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': 'diner',\n",
       "   'cityname': '广州市',\n",
       "   'type': '餐饮服务;餐饮相关场所;餐饮相关',\n",
       "   'photos': [],\n",
       "   'typecode': '050000',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '从化区',\n",
       "   'name': '叶龙老武汉烧烤',\n",
       "   'location': '113.679286,23.632573',\n",
       "   'tel': '15918718710;13125030232',\n",
       "   'shopid': [],\n",
       "   'id': 'B0G1393J7X'},\n",
       "  {'parent': [],\n",
       "   'address': '从化温泉镇中山大学南方学院明辩路2号',\n",
       "   'distance': '0',\n",
       "   'biz_ext': {'cost': [], 'rating': '1.0', 'meal_ordering': '0'},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': 'diner',\n",
       "   'cityname': '广州市',\n",
       "   'type': '餐饮服务;餐饮相关场所;餐饮相关',\n",
       "   'photos': [],\n",
       "   'typecode': '050000',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '从化区',\n",
       "   'name': '网红小串店',\n",
       "   'location': '113.679286,23.632573',\n",
       "   'tel': '13802426981',\n",
       "   'shopid': [],\n",
       "   'id': 'B0FFLNRH1K'},\n",
       "  {'parent': [],\n",
       "   'address': '温泉镇中山大学南方学院后门润泰超市一楼05号商铺',\n",
       "   'distance': '0',\n",
       "   'biz_ext': {'cost': [], 'rating': [], 'meal_ordering': '0'},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': 'diner',\n",
       "   'cityname': '广州市',\n",
       "   'type': '餐饮服务;餐饮相关场所;餐饮相关',\n",
       "   'photos': [],\n",
       "   'typecode': '050000',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '从化区',\n",
       "   'name': '过气轻食屋',\n",
       "   'location': '113.679286,23.632573',\n",
       "   'tel': '13049636920',\n",
       "   'shopid': [],\n",
       "   'id': 'B0FFKTDMOI'},\n",
       "  {'parent': [],\n",
       "   'address': '温泉镇中山大学南方学院后门润泰超市一楼05号商铺',\n",
       "   'distance': '0',\n",
       "   'biz_ext': {'cost': [], 'rating': [], 'meal_ordering': '0'},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': 'diner',\n",
       "   'cityname': '广州市',\n",
       "   'type': '餐饮服务;餐饮相关场所;餐饮相关',\n",
       "   'photos': [],\n",
       "   'typecode': '050000',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '从化区',\n",
       "   'name': '莫凡烧烤',\n",
       "   'location': '113.679286,23.632573',\n",
       "   'tel': '13929768267',\n",
       "   'shopid': [],\n",
       "   'id': 'B0FFKT4WNY'},\n",
       "  {'parent': [],\n",
       "   'address': '温泉大道882号旁润泰超市一楼商铺',\n",
       "   'distance': '0',\n",
       "   'biz_ext': {'cost': [], 'rating': [], 'meal_ordering': '0'},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': 'diner',\n",
       "   'cityname': '广州市',\n",
       "   'type': '餐饮服务;冷饮店;冷饮店',\n",
       "   'photos': [],\n",
       "   'typecode': '050700',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '从化区',\n",
       "   'name': 'LV柠檬茶',\n",
       "   'location': '113.679286,23.632573',\n",
       "   'tel': '15018428578',\n",
       "   'shopid': [],\n",
       "   'id': 'B0FFIIQNQ7'},\n",
       "  {'parent': [],\n",
       "   'address': '温泉镇中山大学南方学院后门润泰超市一楼05号商铺',\n",
       "   'distance': '0',\n",
       "   'biz_ext': {'cost': [], 'rating': [], 'meal_ordering': '0'},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': 'diner',\n",
       "   'cityname': '广州市',\n",
       "   'type': '餐饮服务;甜品店;甜品店',\n",
       "   'photos': [],\n",
       "   'typecode': '050900',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '从化区',\n",
       "   'name': '味美轩(中大店)',\n",
       "   'location': '113.679286,23.632571',\n",
       "   'tel': '15915874513',\n",
       "   'shopid': [],\n",
       "   'id': 'B0G2T96S9V'},\n",
       "  {'parent': [],\n",
       "   'address': '中山大学南方学院',\n",
       "   'distance': '0',\n",
       "   'biz_ext': {'cost': [], 'rating': '4.7', 'meal_ordering': '0'},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': 'diner',\n",
       "   'cityname': '广州市',\n",
       "   'type': '餐饮服务;中餐厅;四川菜(川菜)',\n",
       "   'photos': [{'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/20080ba9f6fcd2808d64ce149b517ca9'},\n",
       "    {'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/9f40694ca108a175d36847d03ecf4ec0'},\n",
       "    {'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/db33127b3da2ffeeabb9bde1157e33cf'}],\n",
       "   'typecode': '050102',\n",
       "   'shopinfo': '1',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '从化区',\n",
       "   'name': '重庆湖边纸包鱼',\n",
       "   'location': '113.679871,23.630292',\n",
       "   'tel': '13924024938',\n",
       "   'shopid': [],\n",
       "   'id': 'B0FFL7NUA2'},\n",
       "  {'parent': [],\n",
       "   'address': '博学路中山大学南方学院后门润泰超市首层23号',\n",
       "   'distance': '1',\n",
       "   'biz_ext': {'cost': [], 'rating': '3.0', 'meal_ordering': '0'},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': 'diner',\n",
       "   'cityname': '广州市',\n",
       "   'type': '餐饮服务;快餐厅;快餐厅',\n",
       "   'photos': [],\n",
       "   'typecode': '050300',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '从化区',\n",
       "   'name': '我家厨房',\n",
       "   'location': '113.679289,23.632563',\n",
       "   'tel': [],\n",
       "   'shopid': [],\n",
       "   'id': 'B0FFK28XPU'},\n",
       "  {'parent': [],\n",
       "   'address': '温泉大道882号',\n",
       "   'distance': '2',\n",
       "   'biz_ext': {'cost': [], 'rating': []},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': [],\n",
       "   'cityname': '广州市',\n",
       "   'type': '生活服务;共享设备;充电宝',\n",
       "   'photos': [],\n",
       "   'typecode': '072101',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '从化区',\n",
       "   'name': '怪兽充电(中山大学南方学院)',\n",
       "   'location': '113.679262,23.632583',\n",
       "   'tel': [],\n",
       "   'shopid': [],\n",
       "   'id': 'B0FFLLU813'},\n",
       "  {'parent': [],\n",
       "   'address': '温泉镇博学路中山大学南方学院后门润泰超市一楼05号商铺',\n",
       "   'distance': '9',\n",
       "   'biz_ext': {'cost': [], 'rating': [], 'meal_ordering': '0'},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': 'diner',\n",
       "   'cityname': '广州市',\n",
       "   'type': '餐饮服务;外国餐厅;日本料理',\n",
       "   'photos': [],\n",
       "   'typecode': '050202',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '从化区',\n",
       "   'name': '井禾寿司',\n",
       "   'location': '113.679193,23.632552',\n",
       "   'tel': '13789117723',\n",
       "   'shopid': [],\n",
       "   'id': 'B0G14PDQVA'},\n",
       "  {'parent': [],\n",
       "   'address': '中山大学南方学院',\n",
       "   'distance': '12',\n",
       "   'biz_ext': {'cost': [], 'rating': [], 'meal_ordering': '0'},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': 'diner',\n",
       "   'cityname': '广州市',\n",
       "   'type': '餐饮服务;外国餐厅;西餐厅(综合风味)',\n",
       "   'photos': [{'provider': [],\n",
       "     'title': [],\n",
       "     'url': 'http://store.is.autonavi.com/showpic/b18ad10223dfdcbd28e244ef56a3229e'}],\n",
       "   'typecode': '050201',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '从化区',\n",
       "   'name': 'Uni-hotel西餐',\n",
       "   'location': '113.679224,23.632671',\n",
       "   'tel': [],\n",
       "   'shopid': [],\n",
       "   'id': 'B0GR3OMDZ2'},\n",
       "  {'parent': [],\n",
       "   'address': '从化温泉镇中山大学南方学院明辩路2号',\n",
       "   'distance': '16',\n",
       "   'biz_ext': {'cost': [], 'rating': [], 'meal_ordering': '0'},\n",
       "   'pname': '广东省',\n",
       "   'importance': [],\n",
       "   'biz_type': 'diner',\n",
       "   'cityname': '广州市',\n",
       "   'type': '餐饮服务;中餐厅;广东菜(粤菜)',\n",
       "   'photos': [],\n",
       "   'typecode': '050103',\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'childtype': [],\n",
       "   'adname': '从化区',\n",
       "   'name': '耀记美食',\n",
       "   'location': '113.679405,23.632673',\n",
       "   'tel': '18816801934',\n",
       "   'shopid': [],\n",
       "   'id': 'B0GRGOTLSL'}],\n",
       " 'status': '1',\n",
       " 'info': 'OK'}"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "key =\"3d66b8511123af91a9b1bb9df9a3c5c6\"\n",
    "location=\"113.679287,23.632575\"\n",
    "arround(key,location,radius='2000')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 多边形搜索"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### ID查询"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 天气查询"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "URL:https://restapi.amap.com/v3/weather/weatherInfo?parameters\n",
    "必填参数：key city\n",
    "选填：extensions(base:返回实况天气,all:返回预报天气) output\n",
    "requests.get()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests,json\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "def weather(key,location,extensions=None,output=None):\n",
    "    url=\"https://restapi.amap.com/v3/weather/weatherInfo?parameters\"\n",
    "    params={\n",
    "        \"key\":key,\n",
    "        \"city\":city,\n",
    "        \"extensions\":extensions,\n",
    "        \"output\":output\n",
    "    }\n",
    "    r=requests.get(url,params=params)\n",
    "    results=r.json()\n",
    "    return results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '1',\n",
       " 'count': '1',\n",
       " 'info': 'OK',\n",
       " 'infocode': '10000',\n",
       " 'lives': [{'province': '广东',\n",
       "   'city': '广州市',\n",
       "   'adcode': '440100',\n",
       "   'weather': '阴',\n",
       "   'temperature': '22',\n",
       "   'winddirection': '东北',\n",
       "   'windpower': '≤3',\n",
       "   'humidity': '53',\n",
       "   'reporttime': '2020-11-14 12:22:36'}]}"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "key =\"3d66b8511123af91a9b1bb9df9a3c5c6\"\n",
    "city=\"440100\"\n",
    "extensions=\"base\"\n",
    "weather(key,city,extensions)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 静态地图"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "使用户能够将高德地图以图片形式嵌入自己的网页中\n",
    "URL:https://restapi.amap.com/v3/staticmap?parameters\n",
    "必填参数：key location(中心点坐标) zoom(地图缩放级别)\n",
    "选填：size scale markers labels paths traffic sig\n",
    "requests.get()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests,json\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [],
   "source": [
    "def ditu(key,location,zoom,size=None,scale=None,markets=None,labels=None,paths=None,traffic=None,sig=None):\n",
    "    url=\"https://restapi.amap.com/v3/staticmap?parameters\"\n",
    "    params={\n",
    "        \"key\":key,\n",
    "        \"location\":location,\n",
    "        \"zoom\":zoom,\n",
    "        \"size\":size,\n",
    "        \"scale\":scale,\n",
    "        \"markets\":markets,\n",
    "        \"labels\":labels,\n",
    "        \"paths\":paths,\n",
    "        \"traffic\":traffic,\n",
    "        \"sig\":sig\n",
    "    }\n",
    "    r=requests.get(url,params=params)\n",
    "    results=r.json()\n",
    "    return results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "ename": "JSONDecodeError",
     "evalue": "Expecting value: line 1 column 1 (char 0)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mJSONDecodeError\u001b[0m                           Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-72-91b95c219f05>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mditu\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"3d66b8511123af91a9b1bb9df9a3c5c6\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m\"113.679287,23.632575\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m\"10\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32m<ipython-input-71-cf6e308f62e1>\u001b[0m in \u001b[0;36mditu\u001b[1;34m(key, location, zoom, size, scale, markets, labels, paths, traffic, sig)\u001b[0m\n\u001b[0;32m     14\u001b[0m     }\n\u001b[0;32m     15\u001b[0m     \u001b[0mr\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mrequests\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0murl\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mparams\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mparams\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 16\u001b[1;33m     \u001b[0mresults\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mr\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mjson\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     17\u001b[0m     \u001b[1;32mreturn\u001b[0m \u001b[0mresults\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\requests\\models.py\u001b[0m in \u001b[0;36mjson\u001b[1;34m(self, **kwargs)\u001b[0m\n\u001b[0;32m    896\u001b[0m                     \u001b[1;31m# used.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    897\u001b[0m                     \u001b[1;32mpass\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 898\u001b[1;33m         \u001b[1;32mreturn\u001b[0m \u001b[0mcomplexjson\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mloads\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtext\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    899\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    900\u001b[0m     \u001b[1;33m@\u001b[0m\u001b[0mproperty\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\json\\__init__.py\u001b[0m in \u001b[0;36mloads\u001b[1;34m(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)\u001b[0m\n\u001b[0;32m    355\u001b[0m             \u001b[0mparse_int\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m \u001b[1;32mand\u001b[0m \u001b[0mparse_float\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m \u001b[1;32mand\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    356\u001b[0m             parse_constant is None and object_pairs_hook is None and not kw):\n\u001b[1;32m--> 357\u001b[1;33m         \u001b[1;32mreturn\u001b[0m \u001b[0m_default_decoder\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdecode\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ms\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    358\u001b[0m     \u001b[1;32mif\u001b[0m \u001b[0mcls\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    359\u001b[0m         \u001b[0mcls\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mJSONDecoder\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\json\\decoder.py\u001b[0m in \u001b[0;36mdecode\u001b[1;34m(self, s, _w)\u001b[0m\n\u001b[0;32m    335\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    336\u001b[0m         \"\"\"\n\u001b[1;32m--> 337\u001b[1;33m         \u001b[0mobj\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mend\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mraw_decode\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ms\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0midx\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0m_w\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ms\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    338\u001b[0m         \u001b[0mend\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0m_w\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ms\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mend\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    339\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mend\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ms\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\json\\decoder.py\u001b[0m in \u001b[0;36mraw_decode\u001b[1;34m(self, s, idx)\u001b[0m\n\u001b[0;32m    353\u001b[0m             \u001b[0mobj\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mend\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mscan_once\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ms\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0midx\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    354\u001b[0m         \u001b[1;32mexcept\u001b[0m \u001b[0mStopIteration\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0merr\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 355\u001b[1;33m             \u001b[1;32mraise\u001b[0m \u001b[0mJSONDecodeError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Expecting value\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0ms\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0merr\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mvalue\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    356\u001b[0m         \u001b[1;32mreturn\u001b[0m \u001b[0mobj\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mend\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mJSONDecodeError\u001b[0m: Expecting value: line 1 column 1 (char 0)"
     ]
    }
   ],
   "source": [
    "ditu(\"3d66b8511123af91a9b1bb9df9a3c5c6\",\"113.679287,23.632575\",\"10\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 输入提示"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "URL:https://restapi.amap.com/v3/assistant/inputtips?parameters\n",
    "请求参数:必填：key keywords\n",
    "选填：type location citylimit city datatype sig output callback"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '1',\n",
       " 'count': '10',\n",
       " 'info': 'OK',\n",
       " 'infocode': '10000',\n",
       " 'tips': [{'id': [],\n",
       "   'name': '肯德基',\n",
       "   'district': [],\n",
       "   'adcode': [],\n",
       "   'location': [],\n",
       "   'address': [],\n",
       "   'typecode': [],\n",
       "   'city': []},\n",
       "  {'id': 'B0FFMDO7PX',\n",
       "   'name': '肯德基',\n",
       "   'district': '广东省广州市海珠区',\n",
       "   'adcode': '440105',\n",
       "   'location': '113.312700,23.100720',\n",
       "   'address': '金菊路10号万宜华轩首层',\n",
       "   'typecode': '050301',\n",
       "   'city': []},\n",
       "  {'id': 'B0GU3LJM7A',\n",
       "   'name': '肯德基',\n",
       "   'district': '广东省广州市越秀区',\n",
       "   'adcode': '440104',\n",
       "   'location': '113.295368,23.124743',\n",
       "   'address': [],\n",
       "   'typecode': '050300',\n",
       "   'city': []},\n",
       "  {'id': 'B0G304H07E',\n",
       "   'name': '肯德基',\n",
       "   'district': '广东省广州市番禺区',\n",
       "   'adcode': '440113',\n",
       "   'location': '113.325686,22.960360',\n",
       "   'address': '钟村街道广东广州市番禺区城区祈福新村祈福缤纷汇7栋',\n",
       "   'typecode': '050300',\n",
       "   'city': []},\n",
       "  {'id': 'B0FFHZAQU0',\n",
       "   'name': '肯德基',\n",
       "   'district': '广东省广州市白云区',\n",
       "   'adcode': '440111',\n",
       "   'location': '113.328485,23.191150',\n",
       "   'address': '京溪南方医院地铁D出口天州广场2楼',\n",
       "   'typecode': '050301',\n",
       "   'city': []},\n",
       "  {'id': 'B0FFGHHGY2',\n",
       "   'name': '肯德基(清湖店)',\n",
       "   'district': '广东省广州市白云区',\n",
       "   'adcode': '440111',\n",
       "   'location': '113.272307,23.256981',\n",
       "   'address': '均禾大道清湖段金铂广场1-2层',\n",
       "   'typecode': '050301',\n",
       "   'city': []},\n",
       "  {'id': 'B00141J8OS',\n",
       "   'name': '肯德基(上社店)',\n",
       "   'district': '广东省广州市天河区',\n",
       "   'adcode': '440106',\n",
       "   'location': '113.367587,23.132552',\n",
       "   'address': '中山大道西上社博兴购物广场2层(近天河公园北门)',\n",
       "   'typecode': '050301',\n",
       "   'city': []},\n",
       "  {'id': 'B00141IEYF',\n",
       "   'name': '肯德基(沙步店)',\n",
       "   'district': '广东省广州市黄埔区',\n",
       "   'adcode': '440112',\n",
       "   'location': '113.526104,23.085144',\n",
       "   'address': '沙步村沙步生活区市场商业街三路壹栋黄埔东路2841号',\n",
       "   'typecode': '050301',\n",
       "   'city': []},\n",
       "  {'id': 'B00141IEYA',\n",
       "   'name': '肯德基(淘金店)',\n",
       "   'district': '广东省广州市越秀区',\n",
       "   'adcode': '440104',\n",
       "   'location': '113.287706,23.139518',\n",
       "   'address': '淘金路淘金街6-8号1楼(世贸大厦后面)',\n",
       "   'typecode': '050301',\n",
       "   'city': []},\n",
       "  {'id': 'B00140B6XN',\n",
       "   'name': '肯德基(黄埔店)',\n",
       "   'district': '广东省广州市黄埔区',\n",
       "   'adcode': '440112',\n",
       "   'location': '113.447521,23.104422',\n",
       "   'address': '大沙地东路5-7号1-2层',\n",
       "   'typecode': '050301',\n",
       "   'city': []}]}"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import requests,json\n",
    "import pandas as pd\n",
    "# 输入提示函数\n",
    "def tishi(key,keywords,city=None,citylimit=None,datatype=None,sig=None,output=None,callback=None):\n",
    "    url=\"https://restapi.amap.com/v3/assistant/inputtips?parameters\"\n",
    "    params={\n",
    "        \"key\":key,\n",
    "        \"keywords\":keywords,\n",
    "        \"city\":city,\n",
    "        \"citylimit\":citylimit,\n",
    "        \"datatype\":datatype,\n",
    "        \"sig\":sig,\n",
    "        \"output\":output,\n",
    "        \"callback\":callback\n",
    "    }\n",
    "    r=requests.get(url,params=params)\n",
    "    results=r.json()\n",
    "    return results\n",
    "tishi(\"3d66b8511123af91a9b1bb9df9a3c5c6\",\"肯德基\",city=\"广州\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 交通态势"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "URL：https://restapi.amap.com/v3/traffic/status/rectangle?parameters\n",
    "参数：\n",
    "必填：key rectangle\n",
    "选填：level() extensions sig output callback "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests,json\n",
    "import pandas as pd\n",
    "# 交通态势函数\n",
    "def jiaotong(key,rectangle,level=None,extensions=None,sig=None,output=None,callback=None):\n",
    "    url=\"https://restapi.amap.com/v3/traffic/status/rectangle?parameters\"\n",
    "    params={\n",
    "        \"key\":key,\n",
    "        \"rectangle\":rectangle,\n",
    "        \"level\":level,\n",
    "        \"extensions\":extensions,\n",
    "        \"sig\":sig,\n",
    "        \"output\":output,\n",
    "        \"callback\":callback    \n",
    "    }\n",
    "    r=requests.get(url,params=params)\n",
    "    results=r.json()\n",
    "    return results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'info': 'INSUFFICIENT_PRIVILEGES',\n",
       " 'infocode': '10012',\n",
       " 'status': '0',\n",
       " 'sec_code_debug': 'd41d8cd98f00b204e9800998ecf8427e',\n",
       " 'key': '3d66b8511123af91a9b1bb9df9a3c5c6',\n",
       " 'sec_code': 'd41d8cd98f00b204e9800998ecf8427e'}"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "peiqi_key=\"3d66b8511123af91a9b1bb9df9a3c5c6\"\n",
    "rectangle=\"116.351147,39.966309;116.357134,39.968727\"\n",
    "jiaotong(peiqi_key,rectangle)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 坐标转换"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "适用场景：够将用户输入的非高德坐标（GPS坐标、mapbar坐标、baidu坐标）转换成高德坐标\n",
    "URL:https://restapi.amap.com/v3/assistant/coordinate/convert?parameters\n",
    "参数:\n",
    "必填:key locations\n",
    "选填:coordsys sig output"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests,json\n",
    "import pandas as pd\n",
    "# 坐标转换函数\n",
    "def zuobiao(key,locations,coordsys=None,sig=None,output=None):\n",
    "    url=\"https://restapi.amap.com/v3/assistant/coordinate/convert?parameters\"\n",
    "    params={\n",
    "        \"key\":key,\n",
    "        \"locations\":locations,\n",
    "        \"coordsys\":coordsys,\n",
    "        \"sig\":sig,\n",
    "        \"output\":output  \n",
    "    }\n",
    "    r=requests.get(url,params=params)\n",
    "    results=r.json()\n",
    "    return results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '1',\n",
       " 'info': 'ok',\n",
       " 'infocode': '10000',\n",
       " 'locations': '113.679226532049,23.632527969614'}"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "peiqi_key=\"3d66b8511123af91a9b1bb9df9a3c5c6\"\n",
    "locations=\"113.685752,23.638368\"\n",
    "zuobiao(peiqi_key,locations,coordsys=\"baidu\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### IP定位"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "API文档：https://lbs.amap.com/api/webservice/guide/api/ipconfig\n",
    "URL:\n",
    "参数:\n",
    "必填:key  #若用户不填写IP，则取客户http之中的请求来进行定位\n",
    "选填:ip sig output"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests,json\n",
    "import pandas as pd\n",
    "# IP定位函数\n",
    "def IP(key,ip=None,sig=None,output=None):\n",
    "    url=\"https://restapi.amap.com/v3/ip?parameters\"\n",
    "    params={\n",
    "        \"key\":key,\n",
    "        \"ip\":ip,\n",
    "        \"sig\":sig,\n",
    "        \"output\":output  \n",
    "    }\n",
    "    r=requests.get(url,params=params)\n",
    "    results=r.json()\n",
    "    return results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '1',\n",
       " 'info': 'OK',\n",
       " 'infocode': '10000',\n",
       " 'province': '广东省',\n",
       " 'city': '广州市',\n",
       " 'adcode': '440100',\n",
       " 'rectangle': '113.1017375,22.93212254;113.6770499,23.3809537'}"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "peiqi_key=\"3d66b8511123af91a9b1bb9df9a3c5c6\"\n",
    "IP(peiqi_key)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "307.2px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
